Skip to content

ci: configure pre-commit.ci to automate PR formatting (#894) - #1918

Open
prateek-dagar wants to merge 1 commit into
py-pdf:masterfrom
prateek-dagar:feature/enable-precommit-ci
Open

ci: configure pre-commit.ci to automate PR formatting (#894)#1918
prateek-dagar wants to merge 1 commit into
py-pdf:masterfrom
prateek-dagar:feature/enable-precommit-ci

Conversation

@prateek-dagar

Copy link
Copy Markdown

Addresses #894

Adds the pre-commit.ci configuration block to .pre-commit-config.yaml to automate formatting checks and auto-fixes for future Pull Requests.

  • Automates PR formatting auto-fixes using Black.
  • Bypasses the local system pylint hook (as system hooks are not supported in the sandboxed CI environment).

Checklist:

  • A unit test is covering the code added / modified by this PR N/A
  • In case of a new feature, docstrings have been added, with also some documentation in the docs/ folder N/A
  • A mention of the change is present in CHANGELOG.md N/A
  • This PR is ready to be merged

@andersonhc

Copy link
Copy Markdown
Collaborator

Thank you @prateek-dagar

Please allow me some time to setup this on a fork and submit a few test commits to test how it works, I'll get back to you as soon as I have some results.

@andersonhc

Copy link
Copy Markdown
Collaborator

@prateek-dagar
I created a pre-commit.ci for my fork and the pre-commit is always failing

CRLF end-lines remover................................................................Passed
Tabs remover..........................................................................Passed
Set file permissions..................................................................Passed
check for merge conflicts.............................................................Passed
check that executables have shebangs..................................................Passed
check that scripts with shebangs are executable.......................................Passed
black.................................................................................Failed
- hook id: black
- files were modified by this hook

reformatted fpdf/actions.py

All done! ✨ 🍰 ✨
1 file reformatted, 231 files left unchanged.

typos.................................................................................Failed
- hook id: typos
- files were modified by this hook
mypy..................................................................................Passed
pyright...............................................................................Failed
- hook id: pyright
- exit code: 1

{'x86': False, 'risc': False, 'lts': False}
Traceback (most recent call last):
  File "/usr/lib/python3.14/urllib/request.py", line 1321, in do_open
    h.request(req.get_method(), req.selector, req.data, headers,
    ~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
              encode_chunked=req.has_header('Transfer-encoding'))
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.14/http/client.py", line 1367, in request
    self._send_request(method, url, body, headers, encode_chunked)
    ~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.14/http/client.py", line 1413, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
    ~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.14/http/client.py", line 1362, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
    ~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.14/http/client.py", line 1122, in _send_output
    self.send(msg)
    ~~~~~~~~~^^^^^
  File "/usr/lib/python3.14/http/client.py", line 1066, in send
    self.connect()
    ~~~~~~~~~~~~^^
  File "/usr/lib/python3.14/http/client.py", line 1501, in connect
    super().connect()
    ~~~~~~~~~~~~~~~^^
  File "/usr/lib/python3.14/http/client.py", line 1032, in connect
    self.sock = self._create_connection(
                ~~~~~~~~~~~~~~~~~~~~~~~^
        (self.host,self.port), self.timeout, self.source_address)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.14/socket.py", line 850, in create_connection
    for res in getaddrinfo(host, port, 0, SOCK_STREAM):
               ~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.14/socket.py", line 987, in getaddrinfo
    for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
               ~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
socket.gaierror: [Errno -3] Temporary failure in name resolution

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<frozen runpy>", line 203, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "/pc/clone/3utqqPhlSaOrXS3eDwnuig/py_env-python3.14/lib/python3.14/site-packages/nodeenv.py", line 1566, in <module>
    main()
    ~~~~^^
  File "/pc/clone/3utqqPhlSaOrXS3eDwnuig/py_env-python3.14/lib/python3.14/site-packages/nodeenv.py", line 1137, in main
    args.node = get_last_stable_node_version()
                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^
  File "/pc/clone/3utqqPhlSaOrXS3eDwnuig/py_env-python3.14/lib/python3.14/site-packages/nodeenv.py", line 1069, in get_last_stable_node_version
    return _get_last_node_version()
  File "/pc/clone/3utqqPhlSaOrXS3eDwnuig/py_env-python3.14/lib/python3.14/site-packages/nodeenv.py", line 1062, in _get_last_node_version
    for v in _get_versions_json() if version_filter(v)), None)
             ~~~~~~~~~~~~~~~~~~^^
  File "/pc/clone/3utqqPhlSaOrXS3eDwnuig/py_env-python3.14/lib/python3.14/site-packages/nodeenv.py", line 1024, in _get_versions_json
    response = urlopen('%s/index.json' % src_base_url)
  File "/pc/clone/3utqqPhlSaOrXS3eDwnuig/py_env-python3.14/lib/python3.14/site-packages/nodeenv.py", line 652, in urlopen
    return urllib2.urlopen(req)
           ~~~~~~~~~~~~~~~^^^^^
  File "/usr/lib/python3.14/urllib/request.py", line 187, in urlopen
    return opener.open(url, data, timeout)
           ~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.14/urllib/request.py", line 487, in open
    response = self._open(req, data)
  File "/usr/lib/python3.14/urllib/request.py", line 504, in _open
    result = self._call_chain(self.handle_open, protocol, protocol +
                              '_open', req)
  File "/usr/lib/python3.14/urllib/request.py", line 464, in _call_chain
    result = func(*args)
  File "/usr/lib/python3.14/urllib/request.py", line 1369, in https_open
    return self.do_open(http.client.HTTPSConnection, req,
           ~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                        context=self._context)
                        ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.14/urllib/request.py", line 1324, in do_open
    raise URLError(err)
urllib.error.URLError: <urlopen error [Errno -3] Temporary failure in name resolution>
Traceback (most recent call last):
  File "/pc/clone/3utqqPhlSaOrXS3eDwnuig/py_env-python3.14/lib/python3.14/site-packages/pyright/node.py", line 93, in _install_node_env
    subprocess.run(args, check=True)
    ~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.14/subprocess.py", line 578, in run
    raise CalledProcessError(retcode, process.args,
                             output=stdout, stderr=stderr)
subprocess.CalledProcessError: Command '['/pc/clone/3utqqPhlSaOrXS3eDwnuig/py_env-python3.14/bin/python', '-m', 'nodeenv', '/tmp/cache/pyright-python/nodeenv']' returned non-zero exit status 1.

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/pc/clone/3utqqPhlSaOrXS3eDwnuig/py_env-python3.14/bin/pyright", line 7, in <module>
    sys.exit(entrypoint())
             ~~~~~~~~~~^^
  File "/pc/clone/3utqqPhlSaOrXS3eDwnuig/py_env-python3.14/lib/python3.14/site-packages/pyright/cli.py", line 31, in entrypoint
    sys.exit(main(sys.argv[1:]))
             ~~~~^^^^^^^^^^^^^^
  File "/pc/clone/3utqqPhlSaOrXS3eDwnuig/py_env-python3.14/lib/python3.14/site-packages/pyright/cli.py", line 18, in main
    return run(*args, **kwargs).returncode
           ~~~^^^^^^^^^^^^^^^^^
  File "/pc/clone/3utqqPhlSaOrXS3eDwnuig/py_env-python3.14/lib/python3.14/site-packages/pyright/cli.py", line 22, in run
    pkg_dir = install_pyright(args, quiet=None)
  File "/pc/clone/3utqqPhlSaOrXS3eDwnuig/py_env-python3.14/lib/python3.14/site-packages/pyright/_utils.py", line 69, in install_pyright
    node.run(
    ~~~~~~~~^
        'npm',
        ^^^^^^
    ...<5 lines>...
        stderr=subprocess.PIPE if silent else sys.stderr,
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "/pc/clone/3utqqPhlSaOrXS3eDwnuig/py_env-python3.14/lib/python3.14/site-packages/pyright/node.py", line 138, in run
    strategy = _resolve_strategy(target)
  File "/pc/clone/3utqqPhlSaOrXS3eDwnuig/py_env-python3.14/lib/python3.14/site-packages/pyright/node.py", line 130, in _resolve_strategy
    return NodeenvStrategy(type='nodeenv', path=_ensure_node_env(target))
                                                ~~~~~~~~~~~~~~~~^^^^^^^^
  File "/pc/clone/3utqqPhlSaOrXS3eDwnuig/py_env-python3.14/lib/python3.14/site-packages/pyright/node.py", line 54, in _ensure_node_env
    _install_node_env()
    ~~~~~~~~~~~~~~~~~^^
  File "/pc/clone/3utqqPhlSaOrXS3eDwnuig/py_env-python3.14/lib/python3.14/site-packages/pyright/node.py", line 95, in _install_node_env
    raise RuntimeError(
        'nodeenv failed; for more reliable node.js binaries try `pip install pyright[nodejs]`'
    ) from exc
RuntimeError: nodeenv failed; for more reliable node.js binaries try `pip install pyright[nodejs]`

Ensure no print() statement appears in fpdf2 sources..................................Passed
Ensure no generate=True is left in a call to assert_pdf_equal().......................Passed
pylint...............................................................................Skipped

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants